import sys
input = lambda: sys.stdin.readline().rstrip()
in_il = lambda: list(map(int, input().split()))
in_sl = lambda: input().split()
in_i = lambda: int(input())
MAX_INT = float('inf')
def solve():
n, k = in_il()
arr = in_il()
for i in range(k):
for j in range(i+k, n, k):
arr[i] = max(arr[i], arr[j])
print(sum(arr[:k]))
for _ in range(in_i()):
solve()
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
long long n, k, j = 1;
long long sum = 0;
cin >> n >> k;
map<int, int> m;
map<int, int>::iterator it;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (m[j] < x)
m[j] = x;
j++;
if (i % k == 0)
j = 1;
}
for (it = m.begin(); it != m.end(); it++)
{
sum = sum + it->second;
}
cout << sum << endl;
}
}
1359A - Berland Poker | 459A - Pashmak and Garden |
1327B - Princesses and Princes | 1450F - The Struggling Contestant |
1399B - Gifts Fixing | 1138A - Sushi for Two |
982C - Cut 'em all | 931A - Friends Meeting |
1594A - Consecutive Sum Riddle | 1466A - Bovine Dilemma |
454A - Little Pony and Crystal Mine | 2A - Winner |
1622B - Berland Music | 1139B - Chocolates |
1371A - Magical Sticks | 1253A - Single Push |
706B - Interesting drink | 1265A - Beautiful String |
214A - System of Equations | 287A - IQ Test |
1108A - Two distinct points | 1064A - Make a triangle |
1245C - Constanze's Machine | 1005A - Tanya and Stairways |
1663F - In Every Generation | 1108B - Divisors of Two Integers |
1175A - From Hero to Zero | 1141A - Game 23 |
1401B - Ternary Sequence | 598A - Tricky Sum |